package com.edu.robot.core.shared;

import com.edu.robot.core.service.ModelManger;
import com.edu.robot.facade.VectorProcessingFacade;
import com.edu.robot.model.Request.TextEmbeddingRequest;
import com.edu.robot.model.enums.ResultCodeEnum;
import com.edu.robot.model.error.BizException;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-03-17 18:34
 **/

@Service
@DubboService(interfaceClass = VectorProcessingFacade.class)
@Slf4j
public class VectorProcessingFacadeImpl implements VectorProcessingFacade {

	@Autowired
	private ModelManger modelManger;


	@Override
	public List<String> vectorProcessing(TextEmbeddingRequest textEmbeddingRequest) {

		log.info("vectorProcessingFacadeImpl,{}", textEmbeddingRequest);

		//获取文本数据
		if(Objects.isNull(textEmbeddingRequest)){

			throw new BizException(ResultCodeEnum.PARAM_INVALID);
		}

		List<Float> vector = new ArrayList<>();

		Optional.ofNullable(textEmbeddingRequest.getText()).ifPresent(text -> {

			Integer token = modelManger.textEmbedding(text, vector);

			log.info("textEmbedding token:{}", token);

		});

		//TODO token
		log.info("VectorProcessingFacadeImpl vectorProcessing:{}",vector);

		List<String> vectorStr = vector.stream().map(String::valueOf).toList();

		return vectorStr;


	}

}
